import PyPDF2

'''
1、读取pdf文件
2、操作内容
3、写入新pdf文件
'''
reader = PyPDF2.PdfReader('resources/demo.pdf')
writer = PyPDF2.PdfWriter()

for no, page in enumerate(reader.pages):
    print(no)
    if no % 2 == 0:
        new_page = page.rotate(-90)   # 逆时针旋转
    else:
        new_page = page.rotate(90)   # 顺时针旋转
    writer.add_page(new_page)  # 旋转后写入新页面

with open('resources/temp.pdf', 'wb') as file_obj:
    writer.write(file_obj)  # 将新生成的页面写入进新pdf文档中